<?php

namespace app\merchant\model;

use app\common\model\WxappHelp as WxappHelpModel;

/**
 * 小程序帮助中心
 * Class WxappHelp
 * @package app\store\model
 */
class WxappHelp extends WxappHelpModel
{
    /**
     * 新增记录
     * @param $data
     * @return false|int
     */
    public function add($param)
    {
        if(!isset($param['title']) || empty($param['title'])){
            $this->error = "请输入标题";
            return false;
        }
        if(!isset($param['content']) || empty($param['content'])){
            $this->error = "请输入内容";
            return false;
        }
        if(!isset($param['sort']) || isZeroNumeric($param['sort'])){
            $this->error = "请输入正确的排序";
            return false;
        }
        $param['wxapp_id'] = self::$wxapp_id;
        return $this->allowField(true)->save($param);
    }

    /**
     * 更新记录
     * @param $param
     * @return bool|int
     */
    public function edit($param)
    {
        if(!isset($param['title']) || empty($param['title'])){
            $this->error = "请输入标题";
            return false;
        }
        if(!isset($param['content']) || empty($param['content'])){
            $this->error = "请输入内容";
            return false;
        }
        if(!isset($param['sort']) || isZeroNumeric($param['sort'])){
            $this->error = "请输入正确的排序";
            return false;
        }
        return $this->allowField(true)->save($param) !== false;
    }

    /**
     * 删除记录
     * @return int
     */
    public function remove() {
        return $this->delete();
    }

}
